home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / SQL Format252808242001.psc / modCommon.bas < prev    next >
Encoding:
BASIC Source File  |  2001-04-25  |  4.5 KB  |  170 lines

  1. Attribute VB_Name = "modCommon"
  2. 'File Open Dialog
  3.  
  4. Public Const OFN_ALLOWMULTISELECT = &H200
  5. Public Const OFN_CREATEPROMPT = &H2000
  6. Public Const OFN_ENABLEHOOK = &H20
  7. Public Const OFN_ENABLETEMPLATE = &H40
  8. Public Const OFN_ENABLETEMPLATEHANDLE = &H80
  9. Public Const OFN_EXPLORER = &H80000
  10. Public Const OFN_EXTENSIONDIFFERENT = &H400
  11. Public Const OFN_FILEMUSTEXIST = &H1000
  12. Public Const OFN_HIDEREADONLY = &H4
  13. Public Const OFN_LONGNAMES = &H200000
  14. Public Const OFN_NOCHANGEDIR = &H8
  15. Public Const OFN_NODEREFERENCELINKS = &H100000
  16. Public Const OFN_NOLONGNAMES = &H40000
  17. Public Const OFN_NONETWORKBUTTON = &H20000
  18. Public Const OFN_NOREADONLYRETURN = &H8000
  19. Public Const OFN_NOTESTFILECREATE = &H10000
  20. Public Const OFN_NOVALIDATE = &H100
  21. Public Const OFN_OVERWRITEPROMPT = &H2
  22. Public Const OFN_PATHMUSTEXIST = &H800
  23. Public Const OFN_READONLY = &H1
  24. Public Const OFN_SHAREAWARE = &H4000
  25. Public Const OFN_SHAREFALLTHROUGH = 2
  26. Public Const OFN_SHAREWARN = 0
  27. Public Const OFN_SHARENOWARN = 1
  28. Public Const OFN_SHOWHELP = &H10
  29.  
  30.  
  31.  
  32. 'OFS_FILE_OPEN_FLAGS and OFS_FILE_SAVE_FLAGS below
  33. 'are mine to save long statements; they're not
  34. 'a standard Win32 type.
  35. Public Const OFS_FILE_OPEN_FLAGS = OFN_EXPLORER _
  36.              Or OFN_LONGNAMES _
  37.              Or OFN_CREATEPROMPT _
  38.              Or OFN_NODEREFERENCELINKS
  39.  
  40. Public Const OFS_FILE_SAVE_FLAGS = OFN_EXPLORER _
  41.              Or OFN_LONGNAMES _
  42.              Or OFN_OVERWRITEPROMPT _
  43.              Or OFN_HIDEREADONLY
  44.  
  45. Public Type OPENFILENAME
  46.     nStructSize As Long
  47.     hwndOwner As Long
  48.     hInstance As Long
  49.     sFilter As String
  50.     sCustomFilter As String
  51.     nCustFilterSize As Long
  52.     nFilterIndex As Long
  53.     sFile As String
  54.     nFileSize As Long
  55.     sFileTitle As String
  56.     nTitleSize As Long
  57.     sInitDir As String
  58.     sDlgTitle As String
  59.     flags As Long
  60.     nFileOffset As Integer
  61.     nFileExt As Integer
  62.     sDefFileExt As String
  63.     nCustDataSize As Long
  64.     fnHook As Long
  65.     sTemplateName As String
  66.  End Type
  67.  
  68. Public OFN As OPENFILENAME
  69.  
  70. Public Declare Function GetOpenFileName Lib "comdlg32.dll" _
  71.     Alias "GetOpenFileNameA" _
  72.    (pOpenfilename As OPENFILENAME) As Long
  73.  
  74. Public Declare Function CommDlgExtendedError _
  75.     Lib "comdlg32.dll" () As Long
  76.  
  77. Public Declare Function GetShortPathName Lib "kernel32" _
  78.     Alias "GetShortPathNameA" _
  79.    (ByVal lpszLongPath As String, _
  80.     ByVal lpszShortPath As String, _
  81.     ByVal cchBuffer As Long) As Long
  82.  
  83.  
  84. Public Function FileSave_Dialog(bShortName As Boolean, strTitle As String, strFileDesc As String, strFilter As String, bAll As Boolean, _
  85.     strFileName As String, OwnerHwnd As Long, Optional strInitDir As String) As String
  86.  
  87.   Dim r As Long
  88.   Dim sp As Long
  89.   Dim LongName As String
  90.   Dim shortName As String
  91.   Dim ShortSize As Long
  92.  
  93.  'to keep lines short(er), I've abbreviated a
  94.  'Null$ to n and n2, and the filter$ to f.
  95.   Dim n As String
  96.   Dim n2 As String
  97.   Dim f As String
  98.   n = Chr$(0)
  99.   n2 = n & n
  100.  
  101.  '------------------------------------------------
  102.  'INITIALIZATION
  103.  '------------------------------------------------
  104.  'fill in the size of the OFN structure
  105.   OFN.nStructSize = Len(OFN)
  106.  
  107.  'assign the owner of the dialog; this can
  108.  'be null if no owner.
  109.   OFN.hwndOwner = OwnerHwnd
  110.  
  111.  'Set filter i.e. *.txt
  112.   f = strFileDesc & n & strFilter
  113.   If bAll Then
  114.     f = f & n & "All Files" & n & "*.*" & n2
  115.   
  116.   End If
  117.     
  118.   OFN.sFilter = f
  119.  
  120.  'Set filter index or which filter is used at startup
  121.  
  122.     OFN.nFilterIndex = 1   '  "User Input"
  123.  
  124. 'Set default file name and space for path
  125.  
  126.     OFN.sFile = strFileName & Space$(1024) & n
  127.     OFN.nFileSize = Len(OFN.sFile)
  128.  
  129.  'default extension applied to a selected file if
  130.  'it has no extension.
  131.   OFN.sDefFileExt = Right$(sFilter, 3) & n
  132.   
  133.  
  134.  'File Title
  135.   OFN.sFileTitle = Space$(512) & n
  136.   OFN.nTitleSize = Len(OFN.sFileTitle)
  137.  
  138.  'Startup directory
  139.  
  140.     If IsNull(strInitDir) Or strInitDir = "" Then
  141.     
  142.         OFN.sInitDir = n
  143.     Else
  144.         OFN.sInitDir = strInitDir & n
  145.     End If
  146. 'Dialog Title
  147.  
  148.   OFN.sDlgTitle = strTitle & n
  149.  
  150.  'flags are the actions and options for the dialog.
  151.   OFN.flags = OFS_FILE_SAVE_FLAGS
  152.  
  153.  'Finally, show the File Open Dialog
  154.   r = GetOpenFileName(OFN)
  155.   
  156.   If r Then
  157.    
  158.     'Path & File Returned (OFN.sFile):
  159.      If bShortName Then
  160.         FileOpen_Dialog = Mid$(OFN.sFile, OFN.nFileOffset + 1, _
  161.                   Len(OFN.sFile) - OFN.nFileOffset - 1)
  162.      Else
  163.         FileOpen_Dialog = OFN.sFile
  164.      End If
  165.  
  166.   End If
  167.  
  168.  
  169. End Function
  170.